package cn.hpclub.server.model;

import java.io.Serializable;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

import cn.hpclub.server.constant.H5ApiConstant;

/**
 * 实体类 - 区县数据
 * 
 */
@TableBind(tableName = "dic_countrycode")
public class CountryCode extends Model<CountryCode> implements Serializable{
    private static final Logger     logger           = LoggerFactory.getLogger(CountryCode.class);
    private static final long       serialVersionUID = 5108597504836776213L;
    public static final CountryCode dao              = new CountryCode();

    public static final String      AREANAME         = "areaname";
    public static final String      PARENT_AREACODE  = "parent_areacode";
    public static final String      AREACODE         = "areacode";

    /**
     * @Title: findAreaByCity
     * @Description:TODO
     * @param city
     * @return List<Record>
     */
    public List<Record> findAreaByCity(String city){
        String sql1 = "select " + AREANAME + " as area";
        String sql2 = "select " + AREACODE;
        String sql3 = " from " + H5ApiConstant.Table.DIC_COUNTRYCODE + " where " + PARENT_AREACODE + " in (select "
                + AREACODE + " from " + H5ApiConstant.Table.DIC_COUNTRYCODE + " where " + AREANAME + " like '" + city
                + "%')";
        String select = sql1 + sql3 + "union select " + AREANAME + " as area from "
                + H5ApiConstant.Table.DIC_COUNTRYCODE + " where " + PARENT_AREACODE + " in (" + sql2 + sql3 + ")";

        return Db.find(select);
    }

}
